<template>
	<view class="game">
		<!-- #ifndef H5 -->
		<view class="head-nav nva-hover"></view>
		<!-- #endif -->
		<view class="releaseTitle">更多赚钱</view>
		
		<view class="into" @click="into">
			<view class="image">
				<image src="../../static/img/06.png" mode="aspectFill"></image>
			</view>
			<view class="right">
				<view class="top">多游赚钱</view>
				<view class="bottom">全新端游戏，试玩赚钱</view>
			</view>
		</view>
		
		<diyTabBar value="game"></diyTabBar>
	</view>
</template>

<script>
	import diyTabBar from '../../component/diy-nav/diy-tabbar.vue'
	export default {
		components: {
			diyTabBar
		},
		data() {
			return {
				imei: null,
				wv: null,
				type: {},
				url: '',
				device_type:1
			}
		},
		onBackPress(options) {
			if (this.wv) {
				this.goback(2);
				return true;
			}
			return false
		},
		onLoad() {
			//#ifdef APP
			uni.hideTabBar()
			//#endif
		},
		onShow() {
			let ua = uni.getSystemInfoSync().platform;
			if (/android/i.test(ua)) {
				// #ifdef APP
				this.getDeviceInfo() //获取设备信息// 安卓
				this.device_type = 2;
				// #endif
			} else {
				// #ifdef APP
				this.type['4'] = this.getIDFA();// 苹果
				this.device_type = 1;
				// #endif
			}
		},
		//
		methods: { 
			into() {
				this.$http.sendrequest('/index/game', {
					device_ids: JSON.stringify(this.type),
					device_type:this.device_type
				}).then(res => {
					this.url = res.data;
					var wv = plus.webview.create(this.url, "dy", {
						'titleNView': {
							backgroundColor: "#FFFFFF",
							titleColor: "#333333",
							titleText: '游戏中心',
							autoBackButton: true,
							cachemode: 'noCache',
						}
					});
					wv.loadURL(this.url)
					wv.addEventListener("loaded", (function() { //android 可写外面   ios的js注入必须在页面加载完成后
						// 这里的JS目录不能随便修改，否则会报错！！！！！！
						wv.appendJsFile('_www/hybrid/html/duoliang.js');
					}));
					wv.addEventListener('close', function() {
						wv = null;
					});
					wv.show();
					var currentWebview = this.$mp.page.$getAppWebview(); //获取当前页面的webview对象
					currentWebview.append(wv); //一定要append到当前的页面里！！！才能跟随当前页面一起做动画，一起关闭 
					this.wv = wv
				})
			},
			goback(delta) {
				const _this = this;
				if (_this.wv) {
					_this.wv.canBack(function(events) {
						console.log(events.canBack)
						if (events.canBack) {
							_this.wv.back();
						} else {
							_this.wv.close();
							currentWebview.remove(wv);
							_this.wv = null;
							uni.navigateBack({
								delta: delta
							})
						}
					})
				}
			},

			getDeviceInfo() {
				let that = this;
				//Android OAID获取方法介绍
				var Build = plus.android.importClass("android.os.Build");
				var androidosv = Build.VERSION.SDK_INT;
				if (androidosv >= 29) {
					plus.device.getOAID({
						success: function(e) {
							that.type['7'] = e.oaid;
						},
						fail: function(e) {
							console.log('getOAID failed: ' + JSON.stringify(e));
							that.msa_oaid = ''
						}
					});
				} else {
					//Android IMEI获取方法介绍
					plus.device.getInfo({
						success: function(e) {
							console.log('getDeviceInfo success: ' + JSON.stringify(e));
						},
						fail: function(e) {
							console.log('getDeviceInfo failed: ' + JSON.stringify(e));
						}
					});
				}
			},

			//获取设备码
			getIDFA() {
				var NSUUID = plus.ios.importClass('NSUUID');
				var UIDevice = plus.ios.importClass("UIDevice");
				var currentDevice = UIDevice.currentDevice()
				var identifierForVendor = currentDevice.identifierForVendor().UUIDString();
				var ASIdentifierManager = plus.ios.importClass("ASIdentifierManager");
				var sharedManager = ASIdentifierManager.sharedManager();
				var advertisingIdentifier = sharedManager.advertisingIdentifier();
				var idfa = plus.ios.invoke(advertisingIdentifier, "UUIDString");
				return idfa;
			}
		}
	}
</script>

<style lang="scss" scoped>
	.game {
		min-height: 100vh;

		.releaseTitle {
			text-align: center;
			line-height: 88rpx;
			font-size: 16px;
			font-family: Arial;
			margin-bottom: 40rpx;
			background: rgb(255, 111, 48);
			color: #FFFFFF;
		}

		.nva-hover {
			background: rgb(255, 111, 48);
		}

		.into {
			padding: 20rpx 20rpx;
			box-sizing: border-box;
			background: #FFFFFF;
			box-shadow: 0px 2px 6px 0px rgba(225, 225, 225, 40);
			display: flex;
			align-items: center;

			.image {
				width: 120rpx;
				height: 120rpx;
				padding: 18rpx;
				background: rgba(255, 111, 48, .1);
				border-radius: 50%;

				image {
					width: 100%;
					height: 100%;
				}
			}

			.right {
				margin-left: 40rpx;
				height: 90rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-between;

				.top {
					color: rgb(255, 111, 48);
					font-size: 30rpx;
					font-weight: bold;
				}

				.bottom {
					font-size: 24rpx;
				}
			}
		}
	}
</style>